package com.ymatou.iapi.dglogin.testcase;

import java.io.IOException;
import java.util.List;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dglogin.parameter.UpdateUnionIdBean;
import com.ymatou.iapi.dglogin.parameter.UserWxInfo;
import com.ymatou.iapi.dglogin.parameter.WxLoginBean;
import com.ymatou.iapi.dglogin.parameter.WxLoginSession;
import com.ymatou.iapi.dglogin.service.UpdateUnionIdCall;
import com.ymatou.iapi.dglogin.service.WxLoginCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.database.model.DGThirdPartyBindInfo;
import com.ymttest.database.sqlwapper.DGUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*完善unionId信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateUnionId{
	private static UpdateUnionIdBean updateunionidBean;
	private static UpdateUnionIdCall updateunionidCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("完善unionId信息");
	}

	@Before
	public void caseUp() {
		updateunionidBean=new UpdateUnionIdBean();
		updateunionidCall=new UpdateUnionIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updateunionidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private WxLoginCall wxlogin(UserCreateBean u) throws ClientProtocolException, IOException {
		WxLoginBean wxloginBean=new WxLoginBean();
		WxLoginCall wxloginCall=new WxLoginCall();
		wxloginBean.setWxAppName(u.getWxAppName());
		wxloginBean.setAppSource(u.getAppSource());
		wxloginBean.setClientIp(TestDataManager.getRandomIp());
		wxloginBean.setJsCode("autotestjscode");
		wxloginBean.setTerminalSource(u.getTerminalSource());
		wxloginBean.setUserType(u.getUserType());
		wxloginCall.addHeader("mock", "mock-enable");
		wxloginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
		wxloginCall.addHeader("mockApi-1", "dgLoginWxClient-getLoginSession-Normal");
		wxloginCall.addHeader("mockParam-1-sessionKey",DGUserCallService.SESSIONKEY);
		wxloginCall.addHeader("mockParam-1-openId",u.getOpenId());
		wxloginCall.addHeader("mockParam-1-unionId",u.getUnionId());
		wxloginCall.setData(wxloginBean);
		wxloginCall.callService();	
		return wxloginCall;
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUnionId_001() {
		Logger.start(true,"完善unionId信息成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			//Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			String nuid="uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000;
			updateunionidBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			//wxLoginSession是从前一个接口wxlogin拿来的那个时候还没有uid
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			updateunionidBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(nuid);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			updateunionidBean.setEncryptedData(encryptedData);
			updateunionidBean.setWxAppName(u.getWxAppName());
			updateunionidCall.setData(updateunionidBean);
			updateunionidCall.callService();			
			
			Logger.verifyEquals("true", updateunionidCall.getString("success"), "验证success");
			
			List<DGThirdPartyBindInfo> list = new DGUserWapper().selectDGThirdPartyOpenId(wxLoginSession.getOpenId());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			Logger.verifyEquals(user, list.get(0).getUserId(), "验证UserId");
			Logger.verifyEquals(UserWxInfo.getUnionId(), list.get(0).getUnionId(), "验证UnionId");
			Logger.verifyEquals("false",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UpdateUnionId_002() {
		Logger.start(true,"不输入UserWxInfo-encryptedData.openid失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			String nuid="uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000;
			updateunionidBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			//wxLoginSession是从前一个接口wxlogin拿来的那个时候还没有uid
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			updateunionidBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
//			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(nuid);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			updateunionidBean.setEncryptedData(encryptedData);
			updateunionidBean.setWxAppName(u.getWxAppName());
			updateunionidCall.setData(updateunionidBean);
			updateunionidCall.callService();			
			
			Logger.verifyEquals("false", updateunionidCall.getString("success"), "验证success");
			//Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UpdateUnionId_003() {
		Logger.start(true,"不输入UserWxInfo-encryptedData.unionId失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			//Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			String nuid="uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000;
			updateunionidBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			//wxLoginSession是从前一个接口wxlogin拿来的那个时候还没有uid
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			updateunionidBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
//			UserWxInfo.setUnionId(nuid);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			updateunionidBean.setEncryptedData(encryptedData);
			updateunionidBean.setWxAppName(u.getWxAppName());
			updateunionidCall.setData(updateunionidBean);
			updateunionidCall.callService();			
			// 不处理不更新 主要验证needUpdateUnionId
			Logger.verifyEquals("true", updateunionidCall.getString("success"), "验证success");
			//Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UpdateUnionId_004() {
		Logger.start(true,"不输入wxAppName失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			String nuid="uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000;
			updateunionidBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			//wxLoginSession是从前一个接口wxlogin拿来的那个时候还没有uid
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			updateunionidBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(nuid);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			updateunionidBean.setEncryptedData(encryptedData);
//			updateunionidBean.setWxAppName(u.getWxAppName());
			updateunionidCall.setData(updateunionidBean);
			updateunionidCall.callService();			
			
			Logger.verifyEquals("false", updateunionidCall.getString("success"), "验证success");
			//Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UpdateUnionId_005() {
		Logger.start(true,"输入错误wxAppName失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			String nuid="uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000;
			updateunionidBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			//wxLoginSession是从前一个接口wxlogin拿来的那个时候还没有uid
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			updateunionidBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(nuid);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			updateunionidBean.setEncryptedData(encryptedData);
			updateunionidBean.setWxAppName("1");
			updateunionidCall.setData(updateunionidBean);
			updateunionidCall.callService();			
			
			//不校验wxappname 只是从数据库中查询存量数据 但是可以用needUpdateUnionId判断结果
			Logger.verifyEquals("true", updateunionidCall.getString("success"), "验证success");
			//Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UpdateUnionId_006() {
		Logger.start(true,"重复调用场景验证");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			//Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			String nuid="uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000;
			updateunionidBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			//wxLoginSession是从前一个接口wxlogin拿来的那个时候还没有uid
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			updateunionidBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(nuid);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			updateunionidBean.setEncryptedData(encryptedData);
			updateunionidBean.setWxAppName(u.getWxAppName());
			updateunionidCall.setData(updateunionidBean);
			updateunionidCall.callService();			
			updateunionidCall.callService();	
			Logger.verifyEquals("true", updateunionidCall.getString("success"), "验证success");
			
			List<DGThirdPartyBindInfo> list = new DGUserWapper().selectDGThirdPartyOpenId(wxLoginSession.getOpenId());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			Logger.verifyEquals(user, list.get(0).getUserId(), "验证UserId");
			Logger.verifyEquals(UserWxInfo.getUnionId(), list.get(0).getUnionId(), "验证UnionId");
			Logger.verifyEquals("false",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UpdateUnionId_007() {
		Logger.start(true,"已有uid的情况下收到更改请求-不变");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
//			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			Logger.verifyEquals("false",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			String nuid="uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000;
			updateunionidBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			//wxLoginSession是从前一个接口wxlogin拿来的那个时候还没有uid
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			updateunionidBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(nuid);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			updateunionidBean.setEncryptedData(encryptedData);
			updateunionidBean.setWxAppName(u.getWxAppName());
			updateunionidCall.setData(updateunionidBean);
			updateunionidCall.callService();			
			
			Logger.verifyEquals("true", updateunionidCall.getString("success"), "验证success");
			
			List<DGThirdPartyBindInfo> list = new DGUserWapper().selectDGThirdPartyOpenId(wxLoginSession.getOpenId());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			Logger.verifyEquals(user, list.get(0).getUserId(), "验证UserId");
			Logger.verifyEquals(u.getUnionId(), list.get(0).getUnionId(), "验证UnionId");
			Logger.verifyEquals("false",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UpdateUnionId_008() {
		Logger.start(true,"不输入encryptedData失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			//Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			String nuid="uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000;
			updateunionidBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			//wxLoginSession是从前一个接口wxlogin拿来的那个时候还没有uid
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			updateunionidBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(nuid);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
//			updateunionidBean.setEncryptedData(encryptedData);
			updateunionidBean.setWxAppName(u.getWxAppName());
			updateunionidCall.setData(updateunionidBean);
			updateunionidCall.callService();			
			
			Logger.verifyEquals("false", updateunionidCall.getString("success"), "验证success");
			//Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UpdateUnionId_009() {
		Logger.start(true,"不输入iv失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			//Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			String nuid="uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000;
//			updateunionidBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			//wxLoginSession是从前一个接口wxlogin拿来的那个时候还没有uid
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			updateunionidBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(nuid);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
//			updateunionidBean.setEncryptedData(encryptedData);
			updateunionidBean.setWxAppName(u.getWxAppName());
			updateunionidCall.setData(updateunionidBean);
			updateunionidCall.callService();			
			
			Logger.verifyEquals("false", updateunionidCall.getString("success"), "验证success");
			//Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
//	@Ignore
	//已删除用户的needUpdateUnionId为false 不会调用到这个接口 - 这个case失败时需要分析修改后的场景
	public void Tc_UpdateUnionId_010() {
		Logger.start(true,"已删除用户完善unionId信息失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			DGUserCallService.DeleteUser(user);
			Logger.verifyEquals("false",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			String nuid="uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000;
			updateunionidBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			//wxLoginSession是从前一个接口wxlogin拿来的那个时候还没有uid
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			updateunionidBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(nuid);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			updateunionidBean.setEncryptedData(encryptedData);
			updateunionidBean.setWxAppName(u.getWxAppName());
			updateunionidCall.setData(updateunionidBean);
			updateunionidCall.callService();			
			
			Logger.verifyEquals("true", updateunionidCall.getString("success"), "验证success");
			
			List<DGThirdPartyBindInfo> list = new DGUserWapper().selectDGThirdPartyOpenId(wxLoginSession.getOpenId());
			Logger.verifyEquals(0, list.size(), "验证有绑定记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUnionId_011() {
		Logger.start(true,"完善unionId信息成功-商家端");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			Logger.verifyEquals("true",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
			String nuid="uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000;
			updateunionidBean.setIv(TestDataManager.getUTF8Base64(DGUserCallService.IV));
//			wxauthloginBean.setIv(DGUserCallService.IV);
			//wxLoginSession是从前一个接口wxlogin拿来的那个时候还没有uid
			WxLoginSession wxLoginSession=new WxLoginSession();
			wxLoginSession.setOpenId(u.getOpenId());
			wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
			wxLoginSession.setUnionId(null);
			String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
			updateunionidBean.setLoginSession(loginSession);
			//加密组装encryptedData
			UserWxInfo UserWxInfo=new UserWxInfo();
			UserWxInfo.setOpenId(u.getOpenId());
			UserWxInfo.setUnionId(nuid);
			UserWxInfo.setAvatarUrl(u.getLogoUrl());
			UserWxInfo.setNickname(u.getNickname());
			UserWxInfo.setGender(1);
			String encryptedData=DGUserCallService.encryptWxEncryptedData(FormatUtil.beanToGSONString(UserWxInfo), DGUserCallService.IV, DGUserCallService.SESSIONKEY);
			updateunionidBean.setEncryptedData(encryptedData);
			updateunionidBean.setWxAppName(u.getWxAppName());
			updateunionidCall.setData(updateunionidBean);
			updateunionidCall.callService();			
			
			Logger.verifyEquals("true", updateunionidCall.getString("success"), "验证success");
			
			List<DGThirdPartyBindInfo> list = new DGUserWapper().selectDGThirdPartyOpenId(wxLoginSession.getOpenId());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			Logger.verifyEquals(user, list.get(0).getUserId(), "验证UserId");
			Logger.verifyEquals(UserWxInfo.getUnionId(), list.get(0).getUnionId(), "验证UnionId");
			Logger.verifyEquals("false",this.wxlogin(u).getString("needUpdateUnionId"),"验证needUpdateUnionId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}